package com.lv.hechuang.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName: MyTimeUtils
 * @Description:
 * @Author: lv
 * @Date: 2021/1/3 14:00
 */
public class MyTimeUtils {
    private static final String DATE_FORMAT_PATTERN_YMD = "yyyy-MM-dd";
    private static final String DATE_FORMAT_PATTERN_YMD_HM = "yyyy-MM-dd HH:mm";
    private final static long minute = 60 * 1000;// 1分钟
    private final static long hour = 60 * minute;// 1小时
    private final static long day = 24 * hour;// 1天
    private final static long month = 31 * day;// 月
    private final static long year = 12 * month;// 年

    /**
     * 返回文字描述的日期
     *
     * @param date
     * @return
     */
    public static String getTimeFormatText(Date date) {

        if (date == null) {
            return null;
        }
        long diff = new Date().getTime() - date.getTime();
        long r = 0;
//        if (diff > year) {
//            r = (diff / year);
//            return r + "年前";
//        }
        if (diff > month || diff >= day) {
//            r = (diff / month);
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(date);
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH) + 1;
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            return year + "年" + month + "月" + day + "日";
        }
//        if (diff > day) {
//            r = (diff / day);
//            return r + "天前";
//        }
//        if (diff > hour) {
//            r = (diff / hour);
//            return r + "小时前";
//        }
        if (diff > minute) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            String minutText = "";
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);
            if (minute == 0) {
                minutText = "00";
            } else {
                minutText = minute + "";
            }
            if (minute < 10) {
                minutText = "0" + minute + "";
            }
            return hour + ":" + minutText;
        } else {
            return "刚刚";
        }
    }

    public static String getTimeDescribe() {
        String timeInfo = "";
        Date d = new Date();
        if (d.getHours() < 11) {
            timeInfo = "早上好";
        } else if (d.getHours() < 13) {
            timeInfo = "中午好";
        } else if (d.getHours() < 18) {
            timeInfo = "下午好";
        } else if (d.getHours() < 24) {
            timeInfo = "晚上好";
        }
        return timeInfo;
    }
}
